import userStore from '@/store/user';
import historyStore from '@/store/history';
import { request } from '@/service/request/request';

const pageSize = 10;

/**
 * 加载用户预测历史记录
 */
export const loadHistoricalRecords = async () => {
    try {
        const userId = userStore.getUserInfo().id;
        const currentPage = historyStore.currentPage;
        const data = {
            userId: userId,
            page: currentPage,
            size: pageSize
        };
        const res = await request('/user/file/get-file-record', data);
        historyStore.addCurrentPage();
        if (res.length < pageSize) {
            historyStore.setLoadFinished(true);
        }
        if (res.length === 0) return;
        historyStore.appendRecords(res);
    } catch (err) {
        throw err;
    }
};

export const deleteRecord = async (id) => {
    try {
        await request('/user/file/delete-user-file', id);
    } catch (err) {
        throw err;
    }
};
